<template>
  <div>
    <a-input @click="openModal" placeholder="请选择"/>
    <t-modal :visible="visible" @ok="handleOk" @cancel="handleCancel">
      <DataGrid v-if="columns.length > 0"
                ref="table"
                :columns="columns"
                :url="url"
                :queryParam="queryParam"
                rowKey="uuid"
                :pageSize="showPageSize"
                :showPagination="showPage"
                :rownumbers="false"
      >
      </DataGrid>
    </t-modal>
  </div>
</template>

<script>
  import {
    DataGrid
  } from "@/components";
  import {
    dataGridMixin
  } from "@/mixins/dataGridMixin";

  export default {
    name: "relatedForm",
    mixins: [dataGridMixin],
    components:{
      DataGrid
    },
    props:{
      options:'',
      tableUuid:'',
      saveValue:'',
      selectColumns:{
        type: Array,
        default:[],
      }
    },
    data(){
      return {
        visible:false,
        showPage:true,
        showPageSize:10,
        // 查询参数
        queryParam: {
          uuid: ''
        },
        url: {
          getPageSet: "/form/formDatabase/formGetPageSet",
          save: "/form/formDatabase/formSave",
          update: "/form/formDatabase/formUpdate",
          deleteBatch: "/form/formDatabase/formDelete",
        },
        columns:[]
      }
    },
    watch:{
      uuid:{
        immediate:true,
        handler(){
          this.queryParam.uuid = this.tableUuid
          this.loadData()
        }
      },
      selectColumns:{
        immediate:true,
        handler(){
          this.columns = []
          this.selectColumns.forEach(item => {
            let obj = {title:item.label,dataIndex: item.key}
            this.columns.push(obj)
          })
        }
      },
    },
    methods:{
      loadData() {
        this.$post("/form/formBasicConfigure/getDetailByUuid", {
          // uuid: this.tableUuid,
          uuid:'5268EB0DFC614CFA8BE5FCE5F4B5CE48'
        }).then((res) => {
          this.drawingList = JSON.parse(res.formList.listJson);
          this.tableDataType = res.formDatabase.type;
          // this.drawingList.listData.forEach(item => {
          //   this.columns.push({
          //     title: item.filedName,
          //     dataIndex: item.filed,
          //   })
          // });
          // this.showPage = this.drawingList.listProData.showPage
          // this.showPageSize = this.drawingList.listProData.showPageSize
          // this.scroll.x = this.columns.length * 100
          // if (this.columns.length > 10) {
          // 	this.columns.splice(11);
          // }
        });
      },
      handleOk(){
        this.visible = false
      },
      handleCancel(){
        this.visible = false
      },
      openModal(){
        this.visible = true;
      },
    },
  }
</script>

<style scoped>

</style>
